<?php

	include_once("include/config.php");
	include_once("include/auth.lib.php");
	include_once("include/functions.php");

	list($status, $user) = auth_get_status();

	if ($status == AUTH_LOGGED) {
	
		$sql = "SELECT a.id, id_palestra, p.nome nome_palestra, cognomenome, categoria, peso, c.desc
		          FROM atleti a 
				  JOIN palestre p ON (a.id_palestra = p.id) 
				  LEFT JOIN categorie c ON (a.categoria = c.id)
				 WHERE id_palestra = ".$user["id_palestra"]." 
				 ORDER BY cognomenome";
		$result = runSQL($sql);
		
		$page = 1;
		$total = mysql_num_rows($result);
		$data = array();
		$data['page'] = $page;
		$data['total'] = $total;
		$data['rows'] = array();
		while ($row = mysql_fetch_assoc($result)) {
			$data['rows'][] = array(
				'id' => $row['id'],
				'cell' => array($row['id'], $row['id_palestra'], $row['nome_palestra'], $row['cognomenome'], $row['desc'], $row['peso'])
			);
		}
		
		echo json_encode($data);
	
	}


?>